package itsm.isperp.framework.data.mybatis.dao;

import itsm.isperp.framework.collection.tree.ITreeNode;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

/**
 * 属性节点的映射器
 * 
 * @author lizx
 * @date 2013-2-15
 * @version V1.0
 */
public interface TreeNodeMapper<T extends ITreeNode> extends CUDMapper<T> {

	/**
	 * 根据id更新树形路径
	 * 
	 * @param treenodePath
	 *            树形路径
	 * @param id
	 *            唯一标识
	 */
	@UpdateProvider(type = TreeNodeTemplate.class, method = "updateTreenodePath")
	public <S extends T> void updateTreenodePath(@Param("entity") S entity,
			@Param("treeNodePath") String treeNodePath,
			@Param("treenodeNamePath") String treenodeNamePath);

	/**
	 * 根据实体的路径进行删除（删除本节点及节点下所有子节点）
	 * 
	 * @param entity
	 *            {@link ITreeNode} 树形实体
	 */
	@DeleteProvider(type = TreeNodeTemplate.class, method = "deleteByTreenodePath")
	public <S extends T> void deleteByTreenodePath(T obj);

	/**
	 * 
	 * @param treenodePath
	 * @param clazz
	 */
	@DeleteProvider(type = TreeNodeTemplate.class, method = "deleteByTreenodePath")
	public <S extends T> void deleteByTreenodePathAndClass(
			@Param("treenodePath") String treenodePath,
			@Param("clazz") Class<?> clazz);

	/**
	 * 更新实体的路径
	 * 
	 * @param entity
	 */
	@UpdateProvider(type = TreeNodeTemplate.class, method = "updatePath")
	public <S extends T> void updatePath(S entity);

	/**
	 * 更新实体的路径及自己点的路径
	 * 
	 * @param entity
	 *            {@link ITreeNode} 树形实体
	 * @param newTreenodePath
	 *            新的路径
	 * @param newTreenodeNamePath
	 *            新的名称路径
	 */
	@UpdateProvider(type = TreeNodeTemplate.class, method = "updateAllPath")
	public <S extends T> void updateAllPath(@Param("entity") S entity,
			@Param("newTreenodePath") String newTreenodePath,
			@Param("newTreenodeNamePath") String newTreenodeNamePath);

	/**
	 * 获取指定父节点下同一名字的节点数目
	 * 
	 * @param name
	 *            节点名称
	 * @param parentId
	 *            父节点id
	 * @return 节点数
	 */
	@SelectProvider(type = TreeNodeTemplate.class, method = "countByParentId")
	public int countByParentId(@Param("name") String name,
			@Param("parentId") String parentId, @Param("clazz") Class<?> clazz);

}
